#!/usr/bin/env python3
from jinja2 import Template

TEMPLATE = """
module matrix_mult_{{size}}x{{size}} #(
  parameter WIDTH = 8
)(
  // 自动生成的接口
);
  // PE阵列生成逻辑
  generate
    {% for i in range(size) %}
    {% for j in range(size) %}
    pe_cell u_pe_{{i}}_{{j}} (
      .a_in(a_bus[{{i}}][{{j}}]),
      .b_in(b_bus[{{i}}][{{j}}]),
      // 自动连接信号
    );
    {% endfor %}
    {% endfor %}
  endgenerate
endmodule
"""

def generate_core(size):
    with open(f"matrix_mult_{size}x{size}.v", "w") as f:
        f.write(Template(TEMPLATE).render(size=size))

if __name__ == "__main__":
    for size in [8, 16, 32]:
        generate_core(size)